home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT8 / PG0804.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  10.9 KB  |  232 lines

  1. ;***********************************************************************
  2. ;
  3. ;  Program PG0804 ( Chapter 8 )
  4. ;
  5. ;  Drawing colored net in graphics mode
  6. ;
  7. ;  Author: A.I.Sopin, VSU, Voronezh, 1992
  8. ;
  9. ;  The low-level technique of programming adapter is used
  10. ;
  11. ;  The 8 pixels of a horizontal line are output at once
  12. ;
  13. ;***********************************************************************
  14. .model  small
  15. EXTRN   VIDTYP : FAR
  16. .stack
  17. .data
  18. ;----------------------------------------------------------
  19. N       DW      0       ;  horizontal knots (0, 1 - 64)
  20. M       DW      0       ;  vertical knots (0, 1 - 40)
  21. X       DW      0       ;  horizontal coordinate of pixel (0 - 639)
  22. Y       DW      0       ;  vertical coordinate of pixel (0 - 339)
  23. H_Leng  DW      640     ;  number of points in horisontal direction
  24. V_Leng  DW      400     ;  number of points in vertical direction
  25. Nstr    DW      0       ;  number of lines for output (1 --- 340)
  26. V_Count DW      0       ;  vertical pixel counter (1 --- 18)
  27. Col     DB      0       ;  color (0 --- 15)
  28. VMODE   DB      0       ;  original video mode
  29. TEXT0   DB      ' Demo program for working in graphics mode  (LOW LEVEL).'
  30.     DB      13,10
  31.     DB      '8 pixels are output at once to increase the speed.'
  32.     DB      13,10
  33.     DB      ' Press any key for change color or ESC to exit.', 7, '$'
  34. TEXT1   DB      13, 10
  35.     DB      ' EGA or VGA  card not installed !  Press any key...', '$'
  36. ;----------------------------------------------------------
  37. .code
  38. .startup
  39.     mov     ah,0Fh                  ;  function 0Fh - get video mode
  40.     int     10h                     ;  BIOS video service call
  41.     mov     VMODE,al                ;  save original video mode
  42.     mov     ah,00                   ;  function 00h - set video mode
  43.     mov     al,03h                  ;  mode 3 (80x25  color)
  44.     int     10h                     ;  BIOS video service call
  45.     mov     ah,2                    ;  function 02h - set cursor
  46.     mov     dx,0100h                ;  initial cursor position - 1, 0
  47.     mov     bh,0                    ;  video page 0
  48.     int     10h                     ;  BIOS video service call
  49. ;  Check whether EGA or VGA installed
  50.     Call    VIDTYP                  ;  determine cideo adapter type
  51.     cmp     al,3                    ;  EGA  or  VGA ?
  52.     jnl     Graph                   ;  OK
  53.     lea     dx,TEXT1                ;  address of string for output
  54.     mov     ah,9                    ;  function 09h - output string
  55.     int     21h                     ;  DOS service call
  56.     mov     ah,0                    ;  function 00h - get key
  57.     int     16h                     ;  BIOS keyboard service call
  58.     jmp     short Exit              ;  to finishing program
  59. ;  Output initial message and set graphics mode
  60. Graph:  lea     dx,TEXT0                ;  address of string for output
  61.     mov     ah,9                    ;  function 09h - output string
  62.     int     21h                     ;  DOS service call
  63.     xor     ah,ah                   ;  function 00h - get key
  64.     int     16h                     ;  BIOS keyboard service call
  65.     mov     ah,0                    ;  function 00h - set video mode
  66.     mov     al,10h                  ;  Color  640x350
  67.     int     10h                     ;  BIOS video service call
  68. ;  Setting the writing mode required
  69.     mov     dx,3CEh                 ;  address register
  70.     mov     al,5                    ;  index for register 5
  71.     out     dx,al                   ;  send index
  72.     inc     dx                      ;  3CFh - mode register
  73.     xor     al,al                   ;  writing mode 0
  74.     out     dx,al                   ;  send writing mode
  75.     mov     Col,0                   ;  initial color (black)
  76.     mov     ax,0A000h               ;  base address of video buffer
  77.     mov     es,ax                   ;  ES points to video buffer
  78. ;-------------------------------------------------------------------
  79. ;  Output colored net into the screen
  80. Loop0:  mov     Nstr,0                  ;  upper line number
  81. Loop1:  Call    HORLINE                 ;  draw horizontal line
  82.     Call    VLINES                  ;  output vertical lines
  83.     add     Nstr,20                 ;  Next Line
  84.     cmp     Nstr,340                ;  Last Line ?
  85.     jl      Loop1                   ;
  86. ;  Change color when a key has been pressed
  87.     xor     ah,ah                   ;  function 00h - get key
  88.     int     16h                     ;  BIOS keyboard service call
  89.     cmp     al,1Bh                  ;  Esc ?
  90.     je      Exit                    ;  yes, finish program
  91.     inc     Col                     ;  change color code
  92.     cmp     Col,15                  ;  all colors shown?
  93.     jng     Loop0                   ;  no, show next color
  94.     mov     Col,0                   ;  set initial color (black)
  95.     jmp     short Loop0             ;  continue
  96. ;-------------------------------------------------------------------
  97. ;  Finish program and return to MS-DOS
  98. Exit:   mov     ax,0FF08h               ;  register number + all bits
  99.     mov     dx,3CEh                 ;  address register
  100.     out     dx,ax                   ;  write mask and mode
  101.     mov     ax,0F02h                ;  index of card mask register
  102.     mov     dx,3C4h                 ;  address register
  103.     out     dx,ax                   ;  send address
  104.     mov     ah,0                    ;  function 0 - set video mode
  105.     mov     al,VMODE                ;  AL - original mode
  106.     int     10h                     ;  BIOS video service call
  107.     mov     ax,4C00h                ;  Function 4Ch - terminate process
  108.     int     21h                     ;  DOS service call
  109. ;-------------------------------------------------------------------
  110. ;
  111. ;  Output pixel onto screen
  112. ;
  113. ;  AL  - color of pixel
  114. ;
  115. ;  CX  - horizontal coordinate  (column) X = (0 --- 640)
  116. ;
  117. ;  DX  - vertical coordinate (row)    Y = (0 --- 340)
  118. ;
  119. ;  ES  - base address of videobuffer ( 0A000h  for 16 colors 640x350)
  120. ;
  121. ;  Registers  AX, BX, SI, DI  are overwritten!
  122. ;
  123. ;-------------------------------------------------------------------
  124. WR_DOT  PROC   NEAR
  125.     mov     si,cx                   ;  horizontal coordinate
  126.     mov     di,dx                   ;  vertical coordinate
  127.     push    ax                      ;  save color
  128. ;  determining the mask for output the bit required
  129.     and     cx,0007h                ;  remainder after dividing by 8
  130.     mov     ah,80h                  ;  mask for 7th bit
  131.     shr     ah,cl                   ;  mask
  132.     mov     dx,3CEh                 ;  address of video register
  133.     mov     al,8                    ;  register's number
  134.     out     dx,ax                   ;  write mode and mask
  135. ;  determining the address of byte in graphics buffer
  136.     mov     bx,si                   ;  X - horizontal coordinate
  137.     shr     bx,1                    ;  /2
  138.     shr     bx,1                    ;  /4
  139.     shr     bx,1                    ;  /8 - offset from start of line
  140.     mov     ax,di                   ;  Y - vertical coordinate
  141.     xor     dx,dx                   ;  clear high part
  142.     mov     cx,80                   ;  multiplier
  143.     mul     cx                      ;
  144.     add     bx,ax                   ;  BX - address of pixel in line
  145.     mov     al,es:[bx]              ;  read latch value
  146. ;  set register of mask for color required
  147.     mov     dx,3C4h                 ;  address register
  148.     mov     ax,0F02h                ;  index of mask register
  149.     out     dx,ax                   ;  set address
  150.     mov     byte ptr es:[bx],0      ;  clear latch
  151.     inc     dx                      ;  3C5h - data register
  152.     pop     ax                      ;  restore color
  153.     out     dx,al                   ;  send color code
  154.     mov     byte ptr es:[bx],0FFh   ;  output pixel ES:[BX]
  155.     mov     cx,si                   ;  horizontal coordinate
  156.     mov     dx,di                   ;  vertical coordinate
  157.     RETN
  158. WR_DOT  ENDP
  159. ;-------------------------------------------------------------------
  160. ;
  161. ;  Output horizontal line (8 pixel ot a time)
  162. ;
  163. ;-------------------------------------------------------------------
  164. HORLINE PROC   NEAR
  165.     xor     cx,cx                   ;  X - initial column for output
  166. HOR1:   mov     dx,3CEh                 ;  address register
  167.     mov     ax,0FF08h               ;  mask and register number
  168.     out     dx,ax                   ;  send mode and mask
  169. ;  Determining an address of byte in video buffer
  170.     mov     bx,cx                   ;  X -horizontal coordinate
  171.     shr     bx,1                    ;  /2
  172.     shr     bx,1                    ;  /4
  173.     shr     bx,1                    ;  /8 - offset from ctart of line
  174.     mov     ax,Nstr                 ;  Y - vertical coordinate
  175.     xor     dx,dx                   ;  clear high part
  176.     mov     si,80                   ;  multiplier
  177.     mul     si                      ;
  178.     add     bx,ax                   ;  BX - address of first pixel in line
  179.     mov     al,es:[bx]              ;  read latch contents
  180. ;  set the mask register for a color
  181.     mov     dx,3C4h                 ;  address register
  182.     mov     ax,0F02h                ;  index of card mask register
  183.     out     dx,ax                   ;  send address
  184.     mov     byte ptr es:[bx],0      ;  clear latch
  185.     inc     dx                      ;  3C5h - data register
  186.     mov     al,Col                  ;  AL - color code
  187.     out     dx,al                   ;  send color code
  188.     mov     byte ptr es:[bx],0FFh   ;  aitpot pixel in  ES:[BX]
  189.     add     cx,8                    ;  number of next byte
  190.     cmp     cx,H_Leng               ;  end of line?
  191.     jl      HOR1                    ;  no, continue output
  192.     RETN                            ;  return to caller
  193. HORLINE ENDP
  194. ;-------------------------------------------------------------------
  195. ;
  196. ;  Drawing vertical lines from knots
  197. ;
  198. ;  Is performed after a horizontal line has been output
  199. ;
  200. ;  CX - horizontal pixel coordinate (row)
  201. ;
  202. ;  DX - vertical pixel coordinate (column)
  203. ;
  204. ;-------------------------------------------------------------------
  205. VLINES  PROC   NEAR
  206.     cmp     Nstr,340                ;  Last Line ?
  207.     je      VLIN5                   ;  yes, return
  208.     cmp     Nstr,0                  ;  first line ?
  209.     jz      VLIN5                   ;  yes, return
  210.     xor     cx,cx                   ;  initial column = 0
  211. VLIN2:  mov     V_Count,20              ;  length of vertical line
  212.     mov     dx,Nstr                 ;  initial row
  213.     sub     dx,19                   ;  number of pixel
  214. ;  Output vertical line from upper line to current line
  215. VLIN3:  mov     al,Col                  ;  pixel color
  216.     Call    WR_DOT                  ;  output pixel
  217.     inc     dx                      ;  address of bottom pixel
  218.     dec     V_Count                 ;
  219.     jg      VLIN3                   ;  continue output
  220. ;  Next knot in horizontal direction
  221.     mov     si,32                   ;  length of string
  222.     and     cx,cx                   ;  begiining of the line?
  223.     jg      VLIN4                   ;  no
  224.     mov     si,31                   ;  to knot 2
  225. VLIN4:  add     cx,si                   ;  next horizontal knot
  226.     cmp     cx,639                  ;  end of line?
  227.     jng     VLIN2                   ;
  228. VLIN5:  RETN                            ;  return
  229. VLINES  ENDP
  230. ;-------------------------------------------------------------------
  231.     END
  232.